#import "IMManager.h"
#import <ImSDK/ImSDK.h>
#import <IMGroupExt/IMGroupExt.h>
#import "IMAGroup.h"
@interface IMManager()
@end
@implementation IMManager
SINGLETON_FOR_CLASS(IMManager);
#pragma mark ————— 初始化IM —————
-(void)initIM{
    IMALoginParam *loginParam = [[IMALoginParam alloc] init];
    [IMAPlatform configWith:loginParam.config];
}
#pragma mark ————— IM登录 —————
-(void)IMLogin:(NSString *)IMID IMPwd:(NSString *)IMPwd completion:(loginBlock)completion{
    TIMLoginParam * login_param = [[TIMLoginParam alloc ]init];
    login_param.identifier = curUser.id;
    login_param.userSig = curUser.user_sign;
    login_param.appidAt3rd = KGlobalVariable.appmodel.sdkappid;
    [[TIMManager sharedInstance] login: login_param succ:^(){
        NSLog(@"Login Succ");
        [self enterBigGroup];
        completion(YES,nil);
    } fail:^(int code, NSString * err) {
        if(curUser != nil)
        {
            [[HUDHelper sharedInstance] tipMessage:err delay:0.3] ;
        }
        userManager.isLogined = NO;
        completion(NO,err);
        NSLog(@"Login Failed: %d->%@", code, err);
    }];
}
#pragma mark 加入大群
- (void)enterBigGroup
{
    if (StrValid(KGlobalVariable.appmodel.group_id))
    {
        [[TIMGroupManager sharedInstance] joinGroup:KGlobalVariable.appmodel.group_id msg:nil succ:^{
             NSLog(ASLocalizedString(@"加入全员广播大群成功"));
        } fail:^(int code, NSString *msg) {
            NSLog(ASLocalizedString(@"加入全员广播大群失败，错误码：%d，错误原因：%@"),code,msg);
        }];
    }
}
#pragma mark ————— IM退出 —————
-(void)IMLogout{
    [[TIMGroupManager sharedInstance] quitGroup:KGlobalVariable.appmodel.group_id succ:^{
        DLog(@"IM 退出成功");
    } fail:^(int code, NSString *msg) {
        NSLog(ASLocalizedString(@"退出在线用户大群失败，错误码：%d，错误原因：%@"),code,msg);
    }];
}
@end
